package com.mdd.admin.controller.order;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.IOrderMenuService;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.order.OrderMenuSearchValidate;
import com.mdd.admin.validate.order.OrderMenuUpdateValidate;
import com.mdd.admin.vo.order.MenuMealVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 菜单
 * @author shenjian
 * @createTime 2023年02月13日 22:57:00
 */
@RestController
@RequestMapping("api/order_menu")
@CrossOrigin
public class OrderMenuController {

    @Resource
    IOrderMenuService iOrderMenuService;

    /**
     * 套餐列表
     *
     * @author shenjian
     * @param pageValidate 分页参数
     * @param searchValidate 搜索参数
     * @return AjaxResult<PageResult<MealVo>>
     */
    @Log(title = "菜单套餐列表")
    @GetMapping("/list")
    public AjaxResult<PageResult<MenuMealVo>> list(@Validated PageValidate pageValidate,
                                                   @Validated OrderMenuSearchValidate searchValidate) {
        PageResult<MenuMealVo> list = iOrderMenuService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @Log(title = "提交菜单套餐")
    @PostMapping("/submit")
    public AjaxResult<?> submit(@Validated @RequestBody OrderMenuUpdateValidate updateValidate) {
        iOrderMenuService.submit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "设置套餐生效")
    @GetMapping("/setValid")
    public AjaxResult<?> setValid(@Validated @IDMust @RequestParam("id") Integer id) {
        iOrderMenuService.setValid(id);
        return AjaxResult.success();
    }

    @Log(title = "获取生效的菜单")
    @GetMapping("/getValid")
    public AjaxResult<?> getValidMenu() {
        return AjaxResult.success(iOrderMenuService.getValidMenu());
    }
}
